home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / builtin2.zoo / meta.c < prev    next >
C/C++ Source or Header  |  1988-08-15  |  3KB  |  149 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24.  
  25. /* meta.c */
  26.  
  27. #include "builtin.h"
  28.  
  29. extern double floatval();
  30. extern word  makefloat();
  31.     
  32. b_VAR()
  33. {
  34.     register word op;
  35.     register pw top;
  36.  
  37.     op = gregc(1);
  38.     deref(op);
  39.     if (isnonvar(op)) {Fail0;}
  40. }
  41.  
  42. b_NONVAR()
  43. {
  44.     register word op;
  45.     register pw top;
  46.  
  47.     op = gregc(1);
  48.     deref(op);
  49.     if (!isnonvar(op)) {Fail0;}
  50. }
  51.  
  52. b_ATOM()
  53.     register word op;
  54.     register pw top;
  55.  
  56.     op = gregc(1);
  57.     deref(op);
  58.     if (!isatom(op)) {Fail0;}
  59. }
  60.  
  61. b_ATOMIC()
  62. {
  63.     register word op;
  64.     register pw top;
  65.  
  66.     op = gregc(1);
  67.     deref(op);
  68.     if (!(isnum(op) || isatom(op))) {Fail0;}
  69. }
  70.  
  71. b_INTEGER()
  72. {
  73.     register word op;
  74.     register pw top;
  75.  
  76.     op = gregc(1);
  77.     deref(op);
  78.     if (!isinteger(op)) {Fail0;}
  79. }
  80.  
  81. b_REAL()
  82. {
  83.     register word op;
  84.     register pw top;
  85.  
  86.     op = gregc(1);
  87.     deref(op);
  88.     if (!isfloat(op)) {Fail0;}
  89. }
  90.  
  91. b_STRUCTURE()
  92. {
  93.     register word op;
  94.     register pw top;
  95.  
  96.     op = gregc(1);
  97.     deref(op);
  98.     if (!(islist(op) || (isconstr(op) && (get_str_arity(op)!=0)))) {Fail0;}
  99. }
  100.  
  101. b_TERMREP() /* r1 is term (var);  r2 is integer that is its rep */
  102. {
  103.     register word op;
  104.     register pw top;
  105.  
  106.     op = gregc(1);
  107.     deref(op);
  108.     if (!unify(makeint(op), gregc(2))) {Fail0;}
  109. }
  110.  
  111. b_DBREF()
  112. {
  113.     register word op;
  114.     register pw top;
  115.     struct psc_rec *psc_ptr;
  116.  
  117.     op = gregc(1); deref(op);
  118.     if ((op&TAGMASK) == CS_TAG) {
  119.     psc_ptr = get_str_psc(op);
  120.     if (get_etype(psc_ptr) != T_BUFF) {Fail0;}
  121.     }
  122.     else {Fail0;}
  123. }    
  124.  
  125. b_FLOOR0()  /* F, I, N */
  126. {
  127. /*  N is bound to a number which gives the direction of conversion:
  128.     if N = 0 then F is bound to a real and I is a variable, while if
  129.     N = 1 then F is a variable and I is bound to an integer.  No
  130.     checking for the above is done.                    */
  131.  
  132.     register word op1, op2, op3;
  133.     register pw top;
  134.  
  135.     op1 = gregc(1); deref(op1);
  136.     op2 = gregc(2); deref(op2);
  137.     op3 = gregc(3); deref(op3);
  138.     if (intval(op3)==0) {    /* F=float, I=free */
  139.     follow(op2) = makeint((word)((int)(floatval(op1))));
  140.     pushtrail(op2);
  141.     }
  142.     else {    /* F=free, I=integer */
  143.     follow(op1) = makefloat((double)(intval(op2)));
  144.     pushtrail(op1);
  145.     };
  146. }
  147.  
  148.